const mqtt = require('mqtt');
const client  = mqtt.connect('mqtt://47.115.225.183');
const MQTT_TOPIC = "Kai/Mqtt";
client.on('connect', function () {
  console.log("已链接至MQTT服务器>>>>>>>>")
  client.subscribe(MQTT_TOPIC, function (err) {
    if (!err) {
      console.log(`已订阅${MQTT_TOPIC}`);
    }
  });
});

client.on('message', function (topic, message) {
  // message is Buffer
  console.log("收w到", + topic + "主题 , 信息：" + message.toString() )
});

client.on('reconnect', function () {
  console.log('reconnecting');
});

client.on('offline', function () {
  console.log('offline');
});